<template>
  <div class="solution-detail">
    <div>
      <BasicBusiness ref="basicBusinessRef" />
    </div>
    <div style="padding: 50px">
      <Step ref="stepRef" />
    </div>
    <el-form
      ref="elForm"
      :model="formData"
      :rules="rules"
      size="mini"
      label-width="160px"
    >
      <el-form-item label="后向合同额" prop="amount">
        <el-input
          v-model="formData.amount"
          placeholder="请输入后向合同额"
          clearable
          :style="{ width: '100%' }"
        ></el-input>
      </el-form-item>
      <el-form-item label="后向合同编号" prop="contractCode">
        <el-input
          v-model="formData.contractCode"
          placeholder="请输入后向合同编号"
          clearable
          :style="{ width: '100%' }"
        ></el-input>
      </el-form-item>
      <el-form-item label="后向合同名称" prop="contractName	">
        <el-input
          v-model="formData.contractName"
          placeholder="请输入后向合同名称"
          clearable
          :style="{ width: '100%' }"
        ></el-input>
      </el-form-item>
      <el-form-item label="后向客户名称" prop="customerName">
        <el-input
          v-model="formData.customerName"
          placeholder="请输入后向客户名称"
          clearable
          :style="{ width: '100%' }"
        ></el-input>
      </el-form-item>
      <el-form-item label="硬件金额" prop="deviceAmount">
        <el-input
          v-model="formData.deviceAmount"
          placeholder="请输入硬件金额"
          clearable
          :style="{ width: '100%' }"
        ></el-input>
      </el-form-item>
      <el-form-item label="服务金额" prop="serviceAmount">
        <el-input
          v-model="formData.serviceAmount"
          placeholder="请输入服务金额"
          clearable
          :style="{ width: '100%' }"
        ></el-input>
      </el-form-item>
      <el-form-item size="mini">
        <el-button type="primary" @click="submitForm">提交</el-button>
        <el-button @click="resetForm">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import BasicBusiness from "@/views/components/business/BasicBusiness.vue";
import Step from "@/views/components/business/Step.vue";
import { getProjectDetail, downContractCirculation } from "@/api/project/index";
export default {
  components: { BasicBusiness, Step },
  props: [],
  data() {
    return {
      formData: {
        amount: "",
        contractCode: "",
        contractName: "",
        customerName: "",
        deviceAmount: "",
        serviceAmount: "",
      },
      rules: {
        amount: [
          {
            required: true,
            message: "请输入后向合同额",
            trigger: "blur",
          },
        ],
        contractCode: [
          {
            required: true,
            message: "请输入后向合同编号",
            trigger: "blur",
          },
        ],
        contractName: [
          {
            required: true,
            message: "请输入后向合同名称",
            trigger: "blur",
          },
        ],
        customerName: [
          {
            required: true,
            message: "请输入后向客户名称",
            trigger: "blur",
          },
        ],
        deviceAmount: [
          {
            required: true,
            message: "请输入硬件金额",
            trigger: "blur",
          },
        ],
        serviceAmount: [
          {
            required: true,
            message: "请输入服务金额",
            trigger: "blur",
          },
        ],
      },
    };
  },
  computed: {
    boId() {
      return this.$route.query.boId;
    },
    projectId() {
      return this.$route.query.projectId;
    },
  },
  watch: {},
  created() {},
  mounted() {
    this.loadData();
  },
  methods: {
    loadData() {
      this.$refs.basicBusinessRef.loadData(this.boId).then((res) => {});

      getProjectDetail(this.boId).then((res) => {
        ;
        this.stage = res.data.stage;
        this.$refs.stepRef.setStage(this.stage);
      });
    },
    submitForm() {
      this.$refs["elForm"].validate((valid) => {
        if (!valid) return;
        // TODO 提交表单
        downContractCirculation({
          ...this.formData,
          boId: this.boId,
          projectId: this.projectId,
        }).then((res) => {
          this.$message({
            message: "操作成功",
            type: "success",
          });
          this.$router.replace("/purchase/index");
        });
      });
    },
    resetForm() {
      this.$refs["elForm"].resetFields();
    },
  },
};
</script>
<style></style>
